function initScore() {
    axios({
        method: 'get',
        url: '/score/list'
    }).then(({
        data: res
    }) => {
        if (res.code == 0) {
            // console.log(res);
            let arr = []
            for (let k in res.data) {
                arr.push(`
            <tr>
                 <th scope="row">${k}</th>
                 <td>${res.data[k].name}</td>
                 <td data-id="${k}"index='1'class="score">${res.data[k].score[0]}</td>
                 <td data-id="${k}"index='2'class="score">${res.data[k].score[1]}</td>
                 <td data-id="${k}"index='3'class="score">${res.data[k].score[2]}</td>
                 <td data-id="${k}"index='4'class="score">${res.data[k].score[3]}</td>
                 <td data-id="${k}"index='5'class="score">${res.data[k].score[4]}</td>
            </tr>  
                 `)
            }
            tbody.innerHTML = arr.join("")
        }
    })
}
let tbody = document.querySelector('tbody')
initScore()
tbody.onclick = function (e) {
    if (!e.target.classList.contains('score')) return
    if (!/^\d{1,3}$/.test(e.target.innerHTML)) return
    let num = e.target.innerHTML
    let input = document.createElement('input')
    input.value = num
    e.target.appendChild(input)
    input.focus()

    input.onblur = function () {
        e.target.innerHTML = num
    }
    input.onkeyup = function (ev) {
        if (ev.key != 'Enter') return
        axios({
            method: 'POST',
            url: '/score/entry',
            data: {
                "stu_id": this.parentNode.getAttribute('data-id'),
                "batch": this.parentNode.getAttribute('index'),
                "score": this.value
            }
        }).then(({
            data: res
        }) => {
            if (res.code == 0) {
                toastr.success('恭喜你,修改成绩成功')
                initScore()
            }
        })
    }
}